/********************************************************************************
* File Name:	mainwindow.cpp
* Description:	第3章 实例11：TabWidget的实例
* Reference book:《Linux环境下Qt4图形界面与MySQL编程》，机械工业出版社.2012.1
* E_mail: openlinux2011@gmail.com
*
********************************************************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLabel>
#include <QPushButton>
#include <QTextEdit>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->tabWidget->setWindowTitle("TabWidget");

    ui->tabWidget->addTab(new QLabel("<h1><font color=blue>Hello!World!</font></h1>"),"QLabel");

    ui->tabWidget->addTab(new QPushButton("Push XD"), "QPushButton");

    ui->tabWidget->addTab(new QTextEdit, "QTextEdit");

    ui->tabWidget->setTabsClosable(true);

    connect(ui->tabWidget,SIGNAL(tabCloseRequested(int)),this,SLOT(removeSubTab(int)));

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::removeSubTab(int index)
{
      ui->tabWidget->removeTab(index);
}

void MainWindow::on_btnAddTab_clicked()
{
    QTextEdit *edit=new QTextEdit;
    edit->setHtml("<h1><font color=red>Hello!World!</font></h1>");
    ui->tabWidget->addTab(edit,"New Tab");
    ui->tabWidget->setCurrentIndex(ui->tabWidget->count()-1);
}
